package org.neuedu.ssmp.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.neuedu.ssmp.crm.entity.Product;
import org.neuedu.ssmp.crm.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService iProductService;

    @RequestMapping("/findModel")
    public List<Product> findModel(){
        List<Product> model = iProductService.findModel();
        return model;
    }

    @RequestMapping("/findAll")
    public List<Product> findAll(){
        return iProductService.list();
    }

    @RequestMapping("/query")
    public List<Product> query(@RequestBody Product product) {
        String name = product.getName();
        String storeName = product.getStoreName();
        System.out.println(name);
        LambdaQueryWrapper<Product> lambdaQueryWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<Product> category1 = lambdaQueryWrapper.like(Product::getName,name);
        LambdaQueryWrapper<Product> category2 = lambdaQueryWrapper.like(Product::getStoreName,storeName);
        return iProductService.list(lambdaQueryWrapper);
    }

    @RequestMapping("/querypro")
    public List<Product> querypro(@RequestBody Product product) {
        String name = product.getName();
        String model = product.getModel();
        System.out.println(name);
        LambdaQueryWrapper<Product> lambdaQueryWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<Product> category1 = lambdaQueryWrapper.like(Product::getName,name);
        LambdaQueryWrapper<Product> category2 = lambdaQueryWrapper.like(Product::getModel,model);
        return iProductService.list(lambdaQueryWrapper);
    }
}
